﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Mvc;
using yiCommerce.Areas.Admin.Models.Orders;
using yiCommerce.Attributes;
using yiCommerce.Attributes.api;
using yiCommerce.Core;
using yiCommerce.Core.Domain.Orders;
using yiCommerce.Core.Domain.Payments;
using yiCommerce.Core.Domain.Securitys;
using yiCommerce.Core.Domain.Shippings;
using yiCommerce.Service.Orders;
using yiCommerce.Service.Securitys;

namespace yiCommerce.Areas.Admin.Controllers.api
{

    [AdminOrderAuthenticationApi]
    public class OrderAdminApiController : ApiController
    {

        private IPermissionService _permissionService;
        private IOrderService _orderService;
        private readonly IWorkContext _workContext;

        public OrderAdminApiController(IPermissionService permissionService, IOrderService orderService, IWorkContext workContext)
        {
            _permissionService = permissionService;
            _orderService = orderService;
            _workContext = workContext;
        }

        [System.Web.Http.HttpPost]
        public OrderSearchModel SearchOrders(OrderSearchFilterModel model)
        {

            int pageIndex = 0;
            int pageSize = 30;

            //load orders
            var orders = _orderService.SearchOrders(0,
                    _workContext.CurrentCustomer.Shop.Id,
                    model.StartDate,
                    model.EndDate,
                    (OrderStatus)model.OrderStatusId,
                    (PaymentStatus)model.PaymentStatusId,
                    (ShippingStatus)model.ShippingStatusId,
                    pageIndex,
                    pageSize);

            var resultModel = new OrderSearchModel { Orders = orders };
            return resultModel;

        }


        public OrderSearchModel Hello()
        {
            return null;
        }
    }
}
